]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
Prefer using g_clear_object/g_clear_pointer macro where possible
authorBilal Elmoussaoui <belmouss@redhat.com>
Wed, 8 Apr 2026 11:53:04 +0000 (13:53 +0200)
committerBilal Elmoussaoui <belmouss@redhat.com>
Wed, 8 Apr 2026 11:57:54 +0000 (13:57 +0200)
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/4162>

src/shell-mount-operation.c
src/st/st-icon.c
src/st/st-scroll-bar.c
src/st/st-texture-cache.c
src/st/st-theme-node.c
src/st/st-widget.c

index a318e554ad82260826b746b926fc67876b0bc1a4..9089cf2777b168250fe0a6993a7f7866879a3b7a 100644 (file)
@@ -83,11 +83,7 @@ shell_mount_operation_show_processes (GMountOperation *operation,
 {
   ShellMountOperation *self = SHELL_MOUNT_OPERATION (operation);
 
-  if (self->pids != NULL)
-    {
-      g_array_unref (self->pids);
-      self->pids = NULL;
-    }
+  g_clear_pointer (&self->pids, g_array_unref);
 
   g_free (self->message);
   g_strfreev (self->choices);
@@ -107,12 +103,7 @@ shell_mount_operation_finalize (GObject *obj)
 
   g_strfreev (self->choices);
   g_free (self->message);
-
-  if (self->pids != NULL)
-    {
-      g_array_unref (self->pids);
-      self->pids = NULL;
-    }
+  g_clear_pointer (&self->pids, g_array_unref);
 
   G_OBJECT_CLASS (shell_mount_operation_parent_class)->finalize (obj);
 }
index 546f620ca06f3cbb788387285d8ebf01a1286a74..d55ca419ed39c7777437bf8ff6dc67100054104d 100644 (file)
@@ -176,17 +176,12 @@ st_icon_dispose (GObject *gobject)
 {
   StIconPrivate *priv = ST_ICON (gobject)->priv;
 
-  if (priv->icon_texture)
-    {
-      clutter_actor_destroy (priv->icon_texture);
-      priv->icon_texture = NULL;
-    }
+  g_clear_pointer (&priv->icon_texture, clutter_actor_destroy);
 
   if (priv->pending_texture)
     {
       clutter_actor_destroy (priv->pending_texture);
-      g_object_unref (priv->pending_texture);
-      priv->pending_texture = NULL;
+      g_clear_object (&priv->pending_texture);
     }
 
   g_clear_signal_handler (&priv->icon_theme_changed_id,
@@ -551,8 +546,7 @@ st_icon_update (StIcon *icon)
   if (priv->pending_texture)
     {
       clutter_actor_destroy (priv->pending_texture);
-      g_object_unref (priv->pending_texture);
-      priv->pending_texture = NULL;
+      g_clear_object (&priv->pending_texture);
       priv->opacity_handler_id = 0;
     }
 
@@ -626,8 +620,7 @@ st_icon_update (StIcon *icon)
     }
   else if (priv->icon_texture)
     {
-      clutter_actor_destroy (priv->icon_texture);
-      priv->icon_texture = NULL;
+      g_clear_pointer (&priv->icon_texture, clutter_actor_destroy);
     }
 }
 
index 056f9870c24ba7b2344a394cc3bcc69281dac106..9529d17952b74e372d0a05039ce8bb2839e3f94c 100644 (file)
@@ -187,17 +187,8 @@ st_scroll_bar_dispose (GObject *gobject)
   if (priv->adjustment)
     st_scroll_bar_set_adjustment (bar, NULL);
 
-  if (priv->handle)
-    {
-      clutter_actor_destroy (priv->handle);
-      priv->handle = NULL;
-    }
-
-  if (priv->trough)
-    {
-      clutter_actor_destroy (priv->trough);
-      priv->trough = NULL;
-    }
+  g_clear_pointer (&priv->handle, clutter_actor_destroy);
+  g_clear_pointer (&priv->trough, clutter_actor_destroy);
 
   G_OBJECT_CLASS (st_scroll_bar_parent_class)->dispose (gobject);
 }
@@ -965,8 +956,7 @@ st_scroll_bar_set_adjustment (StScrollBar  *bar,
       g_signal_handlers_disconnect_by_func (priv->adjustment,
                                             on_changed,
                                             bar);
-      g_object_unref (priv->adjustment);
-      priv->adjustment = NULL;
+      g_clear_object (&priv->adjustment);
     }
 
   if (adjustment)
index a30ebfa56a409e59a6a853d5c5227ae2595164b5..daba9f6bb0790209524fd680c7b7dddd6da5dfce 100644 (file)
@@ -301,17 +301,10 @@ texture_load_data_free (gpointer p)
 {
   AsyncTextureLoadData *data = p;
 
-  if (data->icon_info)
-    {
-      g_object_unref (data->icon_info);
-      if (data->colors)
-        st_icon_colors_unref (data->colors);
-    }
-  else if (data->file)
-    g_object_unref (data->file);
-
-  if (data->key)
-    g_free (data->key);
+  g_clear_object (&data->icon_info);
+  g_clear_pointer (&data->colors, st_icon_colors_unref);
+  g_clear_object (&data->file);
+  g_clear_pointer (&data->key, g_free);
 
   if (data->actors)
     g_slist_free_full (data->actors, (GDestroyNotify) g_object_unref);
index 8fbb71a107454ba8b568d4e05417d4cc6b7991ff..7cfea44b8a080e62ac948ad148b3a00cb29b4a9f 100644 (file)
@@ -64,17 +64,12 @@ maybe_free_properties (StThemeNode *node)
 {
   if (node->properties)
     {
-      g_free (node->properties);
-      node->properties = NULL;
+      g_clear_pointer (&node->properties, g_free);
       node->n_properties = 0;
     }
 
-  if (node->inline_properties)
-    {
-      /* This destroys the list, not just the head of the list */
-      cr_declaration_destroy (node->inline_properties);
-      node->inline_properties = NULL;
-    }
+  /* This destroys the list, not just the head of the list */
+  g_clear_pointer (&node->inline_properties, cr_declaration_destroy);
 }
 
 static void
@@ -82,23 +77,9 @@ st_theme_node_dispose (GObject *gobject)
 {
   StThemeNode *node = ST_THEME_NODE (gobject);
 
-  if (node->parent_node)
-    {
-      g_object_unref (node->parent_node);
-      node->parent_node = NULL;
-    }
-
-  if (node->border_image)
-    {
-      g_object_unref (node->border_image);
-      node->border_image = NULL;
-    }
-
-  if (node->icon_colors)
-    {
-      st_icon_colors_unref (node->icon_colors);
-      node->icon_colors = NULL;
-    }
+  g_clear_object (&node->parent_node);
+  g_clear_object (&node->border_image);
+  g_clear_pointer (&node->icon_colors, st_icon_colors_unref);
 
   st_theme_node_paint_state_free (&node->cached_state);
 
index 226141ac226a43326dc1af272786af7a7415f2cc..983263f0ef3873ebdb48a228b5b232c183d08a86 100644 (file)
@@ -257,8 +257,7 @@ st_widget_remove_transition (StWidget *widget)
   if (priv->transition_animation)
     {
       g_object_run_dispose (G_OBJECT (priv->transition_animation));
-      g_object_unref (priv->transition_animation);
-      priv->transition_animation = NULL;
+      g_clear_object (&priv->transition_animation);
     }
 }
 
@@ -2382,8 +2381,7 @@ st_widget_set_label_actor (StWidget     *widget,
 
   if (priv->label_actor != label)
     {
-      if (priv->label_actor)
-        g_object_unref (priv->label_actor);
+      g_clear_object (&priv->label_actor);
 
       if (label != NULL)
         priv->label_actor = g_object_ref (label);